package com.hibiscusking.basic.service.impl;

import com.hibiscusking.basic.mapper.BaseMapper;
import com.hibiscusking.basic.query.BaseQuery;
import com.hibiscusking.basic.service.IBaseService;
import com.hibiscusking.basic.util.PageList;
import com.hibiscusking.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    public void dele(Long id) {
        baseMapper.dele(id);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public Integer findcount(BaseQuery baseQuery) {
        return baseMapper.findcount(baseQuery);
    }

    @Override
    public PageList<T> queryByPage(BaseQuery baseQuery) {
        Integer totals = baseMapper.findcount(baseQuery);
        if (totals == 0 || totals == null) {
            return new PageList<>(0,new ArrayList<>());
        };
        List<T> departmentList = baseMapper.queryByPage(baseQuery);
//        List<T> objects = new ArrayList<>();
//        int a = 0;
//        for(int i = baseQuery.getStart();a == baseQuery.getPageSize();i++) {
//            a++;
//            T t = departmentList.get(i);
//            System.out.println(t +"dasfsgrgw49653fs");
//            objects.add(t);
//        }
        return new PageList<>(totals,departmentList);
    }

    @Override
    public void batchDele(List ids) {
        baseMapper.batchDele(ids);
    }
}
